home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / v20_bug.arc / V20_BUG.DOC < prev   
Text File  |  1986-01-10  |  3KB  |  87 lines

  1.                          NEC V20/V30 Bug
  2.                          Howard Vigorita
  3.                  New York Amateur Computer Club
  4.  
  5. I recently saw a message from Jonathan Platt on a Florida bulletin
  6. board which mentioned rumors of a bug in the NEC V20/V30 processor.
  7. For those of you that are interested, I've documented the bug below
  8. using a V30 chip. Basically, the NEC chips fail to implement the 2
  9. byte version of the POP instruction. This is not a serious bug;
  10. the Intel register PUSH & POP instructions are duplicated in two
  11. sets of instructions and all the assemblers and compilers I've seen
  12. default to the shorter single byte set in favor of the two byte
  13. set.
  14.  
  15. For those unfamiliar with the longer PUSH/POP form, the two byte
  16. form of the PUSH (which works) will be shown first. The 'debug'
  17. program is fed input from the 'testpush' file. The AX register is
  18. loaded with FFFF hex, pushed onto the stack with the two byte PUSH,
  19. then POPed into the CX register with the single byte POP opcode.
  20. Note that the two byte PUSH is entered using a DB to load in the
  21. FFF0 opcode. The '-u' command issued below shows that although
  22. debug's '-a' command defaults to the short form POP, the long form
  23. is interpreted properly when encountered. 
  24.  
  25.     A>debug < testpush
  26.  
  27.     -a 100
  28.  
  29.     0A7F:0100 mov ax,ffff
  30.     0A7F:0103 db ff,f0
  31.     0A7F:0105 pop cx
  32.     0A7F:0106 nop
  33.     0A7F:0107 
  34.  
  35.     -u 100,106
  36.  
  37.     0A7F:0100 B8FFFF        MOV     AX,FFFF                            
  38.     0A7F:0103 FFF0          PUSH    AX                                 
  39.     0A7F:0105 59            POP     CX                                 
  40.     0A7F:0106 90            NOP                                        
  41.  
  42.     -g =100 106
  43.                      
  44.      AX=FFFF  BX=0000  CX=FFFF  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000  
  45.      DS=0A7F  ES=0A7F  SS=0A7F  CS=0A7F  IP=0106   NV UP DI PL NZ NA PO NC 
  46.      0A7F:0106 90            NOP                                        
  47.  
  48.     -q
  49.  
  50. The CX register ended up with FFFF hex as expected.
  51.  
  52. But the inverse operation does not work on the NEC chip. Below, 'testpop'
  53. feeds input to 'debug'. The AX register is loaded with FFFF, a one byte
  54. opcode PUSH AX is done, followed by the two byte form of the POP into CX.
  55. Again, the two byte POP is implemented by DB'ing its 8FC1 opcode. Although
  56. the SP register (stack pointer) is properly adjusted by the POP, the FFFF
  57. hex does not end up in CX as it should:
  58.  
  59.     A>debug < testpop
  60.  
  61.     -a 100
  62.  
  63.     0A7F:0100 mov ax,ffff
  64.     0A7F:0103 push ax
  65.     0A7F:0104 db 8f,c1
  66.     0A7F:0106 nop
  67.     0A7F:0107
  68.  
  69.     -u 100,106
  70.  
  71.     0A7F:0100 B8FFFF        MOV     AX,FFFF                            
  72.     0A7F:0103 50            PUSH    AX                                 
  73.     0A7F:0104 8FC1          POP     CX                                 
  74.     0A7F:0106 90            NOP                                        
  75.  
  76.     -g =100 106
  77.  
  78.      AX=FFFF  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000  
  79.      DS=0A7F  ES=0A7F  SS=0A7F  CS=0A7F  IP=0106   NV UP DI PL NZ NA PO NC 
  80.      0A7F:0106 90            NOP                                        
  81.  
  82.     -q
  83.  
  84. The above 'feature' can be exploited in distinguishing between NEC and
  85. Intel chips. It is much simpler than the technique of issuing a unique
  86. NEC instruction and intercepting the error trap interrupt.
  87.